#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
int main(){
    // Open camera
    cv::VideoCapture input_stream(0);
        // check
    if(!input_stream.isOpened()){
        std::cerr<<"Could not open camera\n";
        return EXIT_FAILURE;
    }
    // Create window
    std::string original_window = "Original Video";
    cv::namedWindow(original_window, cv::WINDOW_NORMAL);
    std::string grayscale_window = "Grayscale Video";
    cv::namedWindow(grayscale_window, cv::WINDOW_NORMAL);
    std::string Canny_edge_window = "Canny Edge Detection";
    cv::namedWindow(Canny_edge_window, cv::WINDOW_NORMAL);

    cv::Mat frame, gray_frame, edge_frame;

    while(true){
        input_stream >> frame;
            // check
        if(frame.empty()){
            break;
        }
        // Convert to grayscale
        cv::cvtColor(frame,gray_frame, cv::COLOR_BGR2GRAY);
        // Canny edge detection
        cv::Canny(frame, edge_frame, 100, 200);
        // Diaplay images
        cv::imshow(original_window,frame);
        cv::imshow(grayscale_window, gray_frame);
        cv::imshow(Canny_edge_window, edge_frame);
        // Press Esc key to exit
        if(cv::waitKey(15) == 27){
            break;
        }
    }
    // Release resource
    input_stream.release();
    cv::destroyAllWindows();
    return 0;


}